package cn.tedu.apiday04;

import java.io.*;
//测试编码转换流 用来作为桥梁，把字节流转成字符流的桥梁，用来解决字符流读写乱码问题。
//乱码：多指中文乱码， 原因是因为你保存时用的码表和打开时用的码表不一样，解决方案就是保持一致
public class Encoding {

    public static void main(String[] args) throws IOException {
        //out();//测试OutputStreamWriter
        //in();//测试InputStreamReader


    }

    private static void in() throws IOException {
        //创建对象
        Reader in = new InputStreamReader(new FileInputStream("E:\\360downloads\\520.txt"));
        //读取数据
        int b = 0;
        while ((b = in.read())!=-1){
            System.out.println(b);
        }
        //释放资源
        in.close();
    }

    private static void out() throws IOException {
        //创建对象
       //Writer out = new OutputStreamWriter(new FileOutputStream("E:\\360downloads\\520.txt"));使用了默认的平台码，编码表
        Writer out = new OutputStreamWriter(new FileOutputStream("E:\\360downloads\\520.txt"),"UTF-8");
        //写出数据
        out.write(97);
        out.write(98);
        out.write("我爱你");
        //释放资源
        out.close();

    }
}
